﻿using UnityEngine;
using System.Collections;

namespace AssetLoad
{
    public class TextureLoader : LoaderBase 
    {
        public IEnumerator LoadTexture(string assetBundleName, LoadCompleteNotify callback) {
#if !FIX_RESOURCE
            AssetBundleManager.Instance.LoadAssetBundle(assetBundleName);
            while (!AssetBundleManager.Instance.IsLoadedAssetBundle(assetBundleName)) {
                yield return null;
            }
            if (callback != null) {
                callback();
            }
#else
            ResourceManager.Instance.LoadResource(assetBundleName);
            yield return 0;
            if (callback != null) {
                callback();
            }
#endif
        }

        public object GetTexture(string assetBundleName, string assetName) {
#if !FIX_RESOURCE
            return AssetBundleManager.Instance.GetAssetFromBundle(assetBundleName, assetName, typeof(Texture2D));
#else
            return ResourceManager.Instance.GetResource(assetBundleName);
#endif
        }

        public void UnloadTexture(string assetBundleName) {
#if !FIX_RESOURCE
            AssetBundleManager.Instance.UnloadAssetBundle(assetBundleName);
#else
            ResourceManager.Instance.UnloadResource(assetBundleName);
#endif
        }


    }
}